package com.wang.di.timer.bean;

import com.wang.di.core.abs.AbstractNameBean;
import com.wang.di.core.exception.BeanInitException;
import com.wang.di.timer.anno.TimerBeanAnno;

public class TimerBean extends AbstractNameBean {
    private Object instance = null;
    private long createTime = 0;

    public TimerBean(Class clz, TimerBeanAnno anno) {
        super(clz, anno);
    }

    @Override
    public Object get() throws BeanInitException {
        boolean isExpired = System.currentTimeMillis() - createTime > 15 * 1000;
        if (isExpired) {
            createTime = System.currentTimeMillis();
            instance = this.create();
        }
        return instance;
    }
}
